<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/14
 * Time: 21:57
 */

namespace Home\Controller;


use Think\Controller;

class UserAddController extends Controller
{
    /**
     *用户注册界面跳转
    **/
    public function UserSkip(){
//        $u_id=session('u_id');
//        if(!empty($u_id)){
//            $this->display('index/userLogin');
//        }
        $getUserType=D('UserType')->getUserType();
        $this->assign('_getUserType',$getUserType);
        $this->display('index/UserAdd');
    }
    /**
     * 用户注册
     **/
    public function UserRegister(){
//        $upload = new \Think\Upload();// 实例化上传类
//        $upload->maxSize=3145728 ;// 设置附件上传大小
//        $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
//        $upload->rootPath = './';
//        $upload->savePath ='./Public/Uploads/'; // 设置附件上传目录
//        $upload->autoSub=false;
//        $upload->saveName = array('uniqid','');
//        $info   =   $upload->uploadOne($_FILES['u_pic']);
//        if(!$info) {// 上传错误提示错误信息
//            $this->error($upload->getError());
//        }else{// 上传成功
//            $pictrueName=$info['savename'];
//        }
        $u_name=I('u_name');
        $u_email=I('u_email');
        $u_pwd=I('u_pwd');
        $u_repwd=I('u_repwd');
        $u_age=I('u_age');
        $u_sex=I('u_sex');
        $u_type_id=I('u_type_id');
        $u_tel=I('u_tel');
        $u_address=I('u_address');
        $u_postcode=I('u_postcode');
        if(empty($u_name)||empty($u_pwd)||empty($u_repwd)||empty($u_sex)||empty($u_tel)||empty($u_email)||empty($u_type_id)){
            $this->error("您输入的信息不能为空！");
        }
        if($u_pwd!=$u_repwd){
            $this->error("您输入的密码不一致");
        }
        $email=D('UserAdd')->getUserEmail($u_email);
        if($email==true){
            $this->error("用户邮箱已被注册！");
        }
        $res=D("UserAdd")->UserRegister($u_name,$u_email,$u_pwd,$u_age,$u_sex,$u_type_id,$u_tel,$u_address,$u_postcode,$pictrueName);
        if($res==true){
            $this->success('注册成功！',U('Home/Index/index'));
        }else{
            $this->error('注册失败！');
        }
    }

}